
var timer
Page({
  data: {
   num:3
  },
  
  /* onLoad() {
    timer= setInterval(()=>{
      var num=this.data.num;
      num--;
      if(num>=0){
        this.setData({
          num
        })
      }else{
        clearInterval(timer)
      }
      console.log(num);
      console.log(timer);
    },1000)
  }, */
  
  onLoad(){
    this.reduceNum()
  },
  
  reduceNum(){
    timer=setTimeout(()=>{
      var num =this.data.num;
      num--;
      if(num>=0){
        this.setData({num})
      }else{
        wx.navigateTo({
          url: '/pages/music/music',
         
        })
      }
      this.reduceNum();
      console.log(num);
    },1000)
  },
  /* 3.事件跳转时，bug：定时器继续执行，   清除定时器 */
  handleClick(){
    clearTimeout(timer);
    wx.navigateTo({
      url: '/pages/music/music',
  })
  }
  
})
